package edu.suse.controller;

import edu.suse.common.base.RespResult;
import edu.suse.service.SysUserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(value = "用户登录数据test",tags = "用户登录接口API")
public class LoginController {

    // 得到Service实例
    @Autowired //自动装配，在Spring容器中找到实现类对象实例，自动匹配
    private SysUserService sysUserService;

    // 登录接口
    @GetMapping(value = "/login")
    @ApiOperation(value = "用户登录接口",notes = "验证用户的用户名和密码",httpMethod = "GET", response = RespResult.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",value = "用户名称",required = true,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "password",value = "登录密码",paramType = "query",dataType = "String",required = true)
    })
    @ApiResponses({
            @ApiResponse(code=0,message="成功"),
            @ApiResponse(code=-1,message="服务发生了一点小故障，请稍后重试"),
            @ApiResponse(code=404,message="资源不存在"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public RespResult login(String username, String password){
        // 调用Service方法，将参数传递过去
        return sysUserService.login(username,password);
    }
}
